package ServletDemo2;



import entity.Books;
import util.GokJDBCUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * Servlet implementation class StudentList
 */
@WebServlet("/BooksList")
public class BooksList extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public BooksList() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 查询所有图书
		List<Books> books = GokJDBCUtil.queryAll("SELECT * FROM books", Books.class);
//		System.out.println(books);
		// 将查询结果存入请求属性
		request.setAttribute("books", books);

		// 转发到 book-management.jsp 页面
		request.getRequestDispatcher("book-management.jsp").forward(request, response);
//		System.out.println("Books List: " + books);

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}